package com.cwnu.onlinemall.service;

import com.cwnu.onlinemall.mapper.MallSpecialcommodityMapper;
import com.cwnu.onlinemall.pojo.MallSpecialcommodity;
import com.cwnu.onlinemall.pojo.MallSpecialcommodityExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecialCommodityServiceImpl implements SpecialCommodityService {
    @Autowired
    MallSpecialcommodityMapper mallSpecialcommodityMapper;
    @Override
    public List<MallSpecialcommodity> SelectAll() {
        return mallSpecialcommodityMapper.selectByExample(null);
    }

    @Override
    public Integer insert(MallSpecialcommodity mallSpecialcommodity) {
        return mallSpecialcommodityMapper.insertSelective(mallSpecialcommodity);
    }

    @Override
    public MallSpecialcommodity selectById(Integer id) {
        return mallSpecialcommodityMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MallSpecialcommodity> selectByCategoryName(String category) {
        MallSpecialcommodityExample mallSpecialcommodityExample=new MallSpecialcommodityExample();
        MallSpecialcommodityExample.Criteria criteria=mallSpecialcommodityExample.or();
        criteria.andCommodityCategoryEqualTo(category);
        List<MallSpecialcommodity> mallSpecialcommodityList = mallSpecialcommodityMapper.selectByExample(mallSpecialcommodityExample);
        return mallSpecialcommodityList;

    }

    @Override
    public Integer updateById(MallSpecialcommodity mallSpecialcommodity) {
        return mallSpecialcommodityMapper.updateByPrimaryKeySelective(mallSpecialcommodity);
    }

    @Override
    public Integer deleteById(Integer id) {
        return mallSpecialcommodityMapper.deleteByPrimaryKey(id);
    }
}
